package com.xiaoxin.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxin.lease.model.entity.FacilityInfo;
import com.xiaoxin.lease.model.entity.RoomFacility;
import com.xiaoxin.lease.web.admin.mapper.FacilityInfoMapper;
import com.xiaoxin.lease.web.admin.service.FacilityInfoService;
import com.xiaoxin.lease.web.admin.service.RoomFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【facility_info(配套信息表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class FacilityInfoServiceImpl extends ServiceImpl<FacilityInfoMapper, FacilityInfo>
    implements FacilityInfoService{

    @Autowired
    RoomFacilityService roomFacilityService;


    @Override
    public List<FacilityInfo> selectByFacilityId(Long facilityId) {
        super.list();
        return List.of();
    }


    /**
     * 根据房间ID查询配套信息
     * @param facilityId
     * @return
     */
    @Override
    public List<FacilityInfo> getRoomFaclity(Long facilityId) {
        List<FacilityInfo> facilityInfoList = new ArrayList<>();
        List<RoomFacility> roomFacilityList = roomFacilityService.list(new LambdaQueryWrapper<RoomFacility>().eq(RoomFacility::getRoomId,facilityId));
        if(roomFacilityList.size()>0){
            facilityInfoList =  super.list(new LambdaQueryWrapper<FacilityInfo>().in(FacilityInfo::getId,roomFacilityList.stream().map(roomFacility -> roomFacility.getFacilityId()).toList()));
        }
        return  facilityInfoList;
    }
}




